/*******************************************************************************
 * Copyright (c) 2012 Clever Devices.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 * 	Clever Devices Interns - 
 * 	Alex Frankel, Andria Young, Kevin Thomas, Nicholas Culpepper, Taner Oztimurlenk, Thomas Volberg
 ******************************************************************************/
package com.framework.beans;


import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;


/**
 * Used for displaying a "Route" on the map.
 * Constructed from pattern data retrieved from the CTA
 * BusTime API
 * 
 * @author AFrankel
 *
 */
public class BusTimeRouteOverlay extends Overlay{
	
	public BusTimeRouteOverlay(Projection projection, ArrayList<GeoPoint> points){
		this.projection = projection;
		geoPoints = points;
	}

	
	/*
	 * draws route data from ArrrayList of GeoPoints
	 * (non-Javadoc)
	 * @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean)
	 */
	@Override
	public void draw(Canvas canvas, MapView mv, boolean shadow) {

		super.draw(canvas, mv, shadow);
		
        Paint   mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(5);
        points = new ArrayList<Point>();
        
        for(int i = 0; i<geoPoints.size(); i++){
        	p = new Point();
        	projection.toPixels(geoPoints.get(i), p);
        	points.add(p);
        }
        
        //GeoPoint gP1 = geoPoints.get(0);
        //GeoPoint gP2 = geoPoints.get(5);

        Point p1 = new Point();
        Point p2 = new Point();
        Path path = new Path();

        //projection.toPixels(gP1, p1);
        //projection.toPixels(gP2, p2);

        //moveTo must be done first
        path.moveTo(points.get(0).x, points.get(0).y);
        
        //afterwards can do lineTo on repeat
        //i.e. for the rest of the geo points
        for(int i = 1; i<geoPoints.size(); i++)
        	path.lineTo(points.get(i).x, points.get(i).y);

        canvas.drawPath(path, mPaint);
    }
	
	
	
	Projection projection;
	ArrayList<GeoPoint> geoPoints;
	ArrayList<Point> points;
	Point p;
}
